package com.linlong.linlongchat.mapper;

import com.linlong.linlongchat.domain.po.Friend;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 华少
 * @since 2024-09-20
 */
public interface FriendMapper extends BaseMapper<Friend> {

    @Select("SELECT friend_account, remark, create_time, update_time FROM friend WHERE user_account = #{userAccount} AND deleted = 0")
    List<Friend> getFriendList(@Param("userAccount") String userAccount);


    @Select("SELECT * FROM friend WHERE user_account = #{userAccount} AND friend_account = #{friendAccount} AND deleted = 0")
    Friend selectFriend(@Param("userAccount") String userAccount, @Param("friendAccount") String friendAccount);

    @Select("SELECT COUNT(*) FROM friend WHERE user_account = #{userAccount} AND friend_account = #{friendAccount} AND deleted = 0")
    int findFriend(@Param("userAccount") String userAccount, @Param("friendAccount") String friendAccount);

    @Update("UPDATE friend SET remark = #{remark}, update_time = NOW() WHERE user_account = #{userAccount} AND friend_account = #{friendAccount} AND deleted = 0")
    void updateRemark(@Param("userAccount") String userAccount, @Param("friendAccount") String friendAccount, @Param("remark") String remark);

    @Update("UPDATE friend SET deleted = 1, update_time = NOW() WHERE user_account = #{userAccount} AND friend_account = #{friendAccount} AND deleted = 0")
    void deleteFriend(@Param("userAccount") String userAccount, @Param("friendAccount") String friendAccount);
}
